/* Copyright (c) 2004-2024 peigen.info. All rights reserved. */

package info.peigen.hotpot.business.customer.manage.convertor;

import cn.hutool.core.bean.BeanUtil;
import info.peigen.hotpot.business.customer.core.domain.Customer;
import info.peigen.hotpot.business.customer.core.repository.entity.CustomerEntity;
import info.peigen.hotpot.business.customer.manage.form.CustomerManageCreateForm;
import info.peigen.hotpot.business.customer.manage.form.CustomerManageEditForm;
import info.peigen.hotpot.business.customer.manage.form.CustomerManageSearchForm;
import info.peigen.hotpot.business.customer.manage.info.CustomerManageInfo;
import info.peigen.hotpot.common.core.util.IdUtil;
import lombok.extern.slf4j.Slf4j;

/**
 * <b>(CustomerManageConvertor)</b>
 * 管理后台领域对象 "客户" 转换器
 *
 * @author Peigen
 * @version 1.0.0
 * @since 2023-09-09
 */
@SuppressWarnings("unused")
@Slf4j
public class CustomerManageConvertor {
    // ConvertToEntity
    public static CustomerEntity convertToEntity(Customer domain) {
        return BeanUtil.copyProperties(domain, CustomerEntity.class);
    }

    public static CustomerEntity convertToEntity(CustomerManageInfo info) {
        return BeanUtil.copyProperties(info, CustomerEntity.class);
    }

    public static CustomerEntity convertToEntity(CustomerManageSearchForm form) {
        return BeanUtil.copyProperties(form, CustomerEntity.class);
    }

    public static CustomerEntity convertToEntity(CustomerManageCreateForm form) {
        if (form.getCustomerId() == null) {
            form.setCustomerId(IdUtil.id());
        }
        return BeanUtil.copyProperties(form, CustomerEntity.class);
    }

    public static CustomerEntity convertToEntity(CustomerManageEditForm form) {
        return BeanUtil.copyProperties(form, CustomerEntity.class);
    }

    // ConvertToDomain
    public static Customer convertToDomain(CustomerEntity entity) {
        return BeanUtil.copyProperties(entity, Customer.class);
    }

    public static Customer convertToDomain(CustomerManageInfo info) {
        return BeanUtil.copyProperties(info, Customer.class);
    }

    public static Customer convertToDomain(CustomerManageSearchForm form) {
        return BeanUtil.copyProperties(form, Customer.class);
    }

    public static Customer convertToDomain(CustomerManageCreateForm form) {
        if (form.getCustomerId() == null) {
            form.setCustomerId(IdUtil.id());
        }
        return BeanUtil.copyProperties(form, Customer.class);
    }

    public static Customer convertToDomain(CustomerManageEditForm form) {
        return BeanUtil.copyProperties(form, Customer.class);
    }

    // convertToInfo
    public static CustomerManageInfo convertToInfo(Customer domain) {
        return BeanUtil.copyProperties(domain, CustomerManageInfo.class);
    }

    public static CustomerManageInfo convertToInfo(CustomerEntity entity) {
        return BeanUtil.copyProperties(entity, CustomerManageInfo.class);
    }

    public static CustomerManageInfo convertToInfo(CustomerManageSearchForm form) {
        return BeanUtil.copyProperties(form, CustomerManageInfo.class);
    }

    public static CustomerManageInfo convertToInfo(CustomerManageCreateForm form) {
        if (form.getCustomerId() == null) {
            form.setCustomerId(IdUtil.id());
        }
        return BeanUtil.copyProperties(form, CustomerManageInfo.class);
    }

    public static CustomerManageInfo convertToInfo(CustomerManageEditForm form) {
        return BeanUtil.copyProperties(form, CustomerManageInfo.class);
    }
}